<template>
  <!-- 搜索工作栏 -->
  <ContentWrap>
    <el-form
      class="-mb-15px"
      :model="queryParams"
      ref="queryFormRef"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="" prop="name">
        <el-select
          v-model="queryParams.filterType"
          class="!w-180px"
          clearable
          placeholder="请选择栏目类型"
        >
          <el-option
            v-for="dict in getIntDictOptions(DICT_TYPE.CMS_CHANNEL_FILTER_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
        <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
      </el-form-item>
    </el-form>
  </ContentWrap>

  <!-- 列表 -->
  <ContentWrap>
    <el-table
      v-loading="loading"
      :data="list"
      row-key="id"
      :default-expand-all="isExpandAll"
      v-if="refreshTable"
    >
      <el-table-column prop="name" label="名称" />
      <el-table-column prop="path" label="访问路径"  />
      <el-table-column prop="views" label="访问量" />
    </el-table>
  </ContentWrap>
</template>
<script setup lang="ts" name="Channel">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import * as ChannelApi from '@/api/cms/channel'
// 列表相关的变量
const loading = ref(true) // 列表的加载中
const list = ref() // 列表的数据
const queryParams = reactive({
  filterType: 2
})
const queryFormRef = ref() // 搜索的表单
const isExpandAll = ref(true) // 是否展开，默认全部展开
const refreshTable = ref(true) // 重新渲染表格状态
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ChannelApi.getChannelViewListApi(queryParams)
    list.value = data
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  getList()
}

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value.resetFields()
  handleQuery()
}
// ========== 初始化 ==========
onMounted(async () => {
  await getList()
})
</script>
<style lang="scss">
.el-row {
  margin-bottom: 10px;
}

.el-row:last-child {
  margin-bottom: 0;
}

.el-col {
  border-radius: 4px;
}

.el-col-10,
.sourceSite {
  width: 240px;
  margin-left: 100px;
}

.matchTitle {
  width: 80%;
}
</style>
